<?php
	class Musers extends Model {
	
		function __construct() {
			parent::Model();
		}
		
		function getAllUsers() {
			$query = $this->db->get('users');
			if ($query->num_rows() > 0){
				return $query->result(); 
			} else {
				show_error('Database is Empty!');
			}  
		}
		
		function getUser($id){
			$options = array('id' => $id);
			$query = $this->db->getwhere('users',$options,1);
			if ($query->num_rows() > 0){
				return $query->result(); 
			}   
		}
		
		function addUser(){
			$data = array( 
				'nickname' => $_POST['nickname'],
				'fb_uid' => $_POST['fb_uid'],
				'email' => $_POST['email'],
				'balance' => 1000,
				'city_id' => 1,
				'current_city' => $_POST['city'], //This will used in conjuction with caching for determining the current location of the user
			);
			$data['created_at'] = date("Y-m-d H:i:s");
			$this->db->insert('users', $data);	
		}
		
		function updateUser ($id){
			$data = array( 
				'nickname' => $_POST['nickname'],
				'fb_uid' => $_POST['fb_uid'],
				'balance' => @$_POST['balance'],
				'city_id' => @$_POST['city_id'],
				'email' => $_POST['email'],
				'current_city' => $_POST['city'] //This will used in conjuction with caching for determining the current location of the user
				);

			$data['updated_at'] = date("Y-m-d H:i:s");
			$this->db->where('id', $id);
			$this->db->update('users', $data);	
		}
		
		function deleteUser($id){
			$this->db->where('id', $id);
			$this->db->delete('users');
		}
	}
?>